from rest_framework import serializers
from recruit.models import Recruit, Enterprise
from user.models import User


# 用户表
class UserSerializer(serializers.ModelSerializer):
    class Meta:
        model = User
        fields = ['id']


# 最新职位,推荐职位
class NewRecruitSerializer2(serializers.ModelSerializer):
    recruits = serializers.IntegerField
    class Meta:
        model = Enterprise
        fields = [
            'id',
            'name',
            'logo',
            'recruits',
            'summary',
            'labels'
        ]


# 最新职位,推荐职位
class NewRecruitSerializer(serializers.ModelSerializer):
    enterprise = NewRecruitSerializer2()

    class Meta:
        model = Recruit
        fields = '__all__'


# 职位详情之企业关联的每个职位，关联的企业，第四层
class EnterpriseFour(serializers.ModelSerializer):
    recruits = serializers.IntegerField()

    class Meta:
        model = Enterprise
        fields = [
            'id',
            'name',
            'labels',
            'logo',
            'summary',
            'recruits',
        ]


# 职位详情之企业关联的多个职位， 第三层
class RecruitsFirst(serializers.ModelSerializer):
    enterprise = EnterpriseFour

    class Meta:
        model = Recruit
        fields = '__all__'


# 职位详情之企业， 第二层
class EnterpriseDetailSerializer(serializers.ModelSerializer):
    users = UserSerializer(many=True)
    recruits = RecruitsFirst(many=True)

    class Meta:
        model = Enterprise
        fields = '__all__'


# 职位详情之职位,第一层
class RecruitDetailSerializer(serializers.ModelSerializer):
    enterprise = EnterpriseDetailSerializer()
    users = UserSerializer(many=True)

    class Meta:
        model = Recruit
        fields = '__all__'


# 职位访问次数
class RecruitAccessNumberSerializer(serializers.ModelSerializer):
    # users = UserSerializer(many=True)

    class Meta:
        model = Recruit
        fields = '__all__'






